<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .myborder{
            background-color: red;
            width: 80px;
            height: 100px;
        }
        .myfont{
            font-size: 20px;
        }
    </style>
</head>
<body>
    <input type="text" id="input">
    <div id="div1" style="color: red;" class="myborder myfont" title="div1">这是div1</div>
    <img src="./img/1.png" height="256px" width="144px" class="img1">
    <script>
        let div1 = document.getElementById("div1")
        div1.title = "xxxxxx"
        div1.style.color = "blue"
        console.log(div1.title)
        div1.setAttribute("title","yyyyyy")
        let title = div1.getAttribute("title")
        let img = document.getElementsByTagName("img")[0]
        img.setAttribute("src","./img/2.png")
        img.style.border = "10px red solid"
        // div1.className = "myborder1 myfont"
        // div1.classList.add("myborder1")
        div1.classList.add("myfont")
        // div1.classList.remove("myborder")
        // div1.classList.toggle("myborder")
        let flag = img.classList.contains("img1")
        console.log(flag)



        // 鼠标事件
        // div1.onclick=()=>{
        //     console.log("321")
        //     div1.classList.toggle("myfont")
        // }
        div1.addEventListener("click",function(){
            console.log("321")
            div1.classList.toggle("myfont")
        })

        img.addEventListener("mouseenter",function(){
            console.log("鼠标移入图片区域")
        })
        img.addEventListener("mouseleave",function(){
            console.log("鼠标移出图片区域")
        })
        img.addEventListener("mousemove",function(){
            console.log("鼠标在图片区域移动")
        })
        

        // 键盘事件
        // input.addEventListener("keydown",()=>{
        //     console.log("键盘被按下")
        // })
        let input = document.getElementById("input")
        input.addEventListener("keyup",(event)=>{
            console.log("键盘某个键按下并抬起",event.key,event.code)
        })
    </script>
</body>
</html>